const express = require('express')
const router = express.Router()
const orderService = require('services/order')

router.get('/order-stat', async (req, res, next) => {
  const { year, month } = req.query
  if (!year || !month) {
    next(new BizError('missing params'))
  }

  const orders = await orderService.getOrdersByMonth(year, month)
  try {
    res.json(orders)
  } catch (e) {
    next(e)
  }
})

router.get('/order-monthly-income', async (req, res, next) => {
  const { year } = req.query
  if (!year) {
    next(new BizError('missing params'))
  }

  const monthTotols = await orderService.getOrderMonthlyIncome(year)
  try {
    res.json(monthTotols)
  } catch (e) {
    next(e)
  }
  orderService.get
})

module.exports = router